package view;

import domain.ATM;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by CatScan on 2016/6/21.
 */
public class PasswordViewController implements ControlledStage, Initializable {
    private StageController myController;
    private ATM atm;

    @FXML
    private PasswordField password;
    @FXML
    private Button verifyPassword;

    public void setStageController(StageController stageController) {
        this.myController = stageController;
    }




    public void initialize(URL location, ResourceBundle resources) {

    }

    public void goToMain(){
        myController.setStage(MainApp.mainViewID);
    }


    @FXML
    private void passwordAction(ActionEvent event) throws IOException {
        atm = myController.getAtm();
        System.out.println("You clicked the Button " + verifyPassword.getId());

        if(atm.enterPassword(password.getText())){
            myController.loadStage(MainApp.mainViewID, MainApp.mainViewRes);
            myController.setStage(MainApp.mainViewID,MainApp.passwordViewID);
        }else {
            atm.setCurMessageType("1");
            myController.setAtm(atm);

            myController.loadStage(MainApp.messageViewID,MainApp.messageViewRes);
            myController.setStage(MainApp.messageViewID);
        };

    }

}

